import logging
import os
from logging.handlers import RotatingFileHandler

from app.config.config import config
from app.settings import env


def set_log():
    config_class = config[env]
    # 设置日志等级
    logging.basicConfig(level=config_class.LOG_LEVEL)
    # 创建日志记录器
    # print(111, os.path.abspath('/log/mumunote.log'))
    file_log_handler = RotatingFileHandler('log/mumunote.log', maxBytes=1024*1024*300, backupCount=10)
    formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(filename)s:%(lineno)s %(message)s')
    file_log_handler.setFormatter(formatter)
    # 为全局的日志工具对象添加日志记录器
    logging.getLogger().addHandler(file_log_handler)


set_log()
